import { HttpCom } from "../net/HttpCom";

export class ModelWeapon {
    private static instance: ModelWeapon | null = null; // 保存单例实例

    public static getInstance(): ModelWeapon {
        if (this.instance === null) {
            this.instance = new ModelWeapon(); // 创建新的实例
        }
        return this.instance; // 返回已存在的实例
    }
    public level: number = 1;
    public grade: string = "SR";
    public getweaponLevel() {
        HttpCom.getWeapon((data) => {
            console.log(data, "武器属性")
            this.grade = data.data.grade;
            this.level = data.data.level;
        })
    }


    formatBytes(bytes: number): string {
        const K = 1000; // 1 K = 1024 Bytes
        const M = K * 1000; // 1 M = 1024 K
        const G = M * 1000; // 1 G = 1024 M
        const T = G * 1000; // 1 T = 1024 G
        const P = T * 1000; // 1 P = 1024 T
        const E = P * 1000; // 1 E = 1024 P
        const Z = E * 1000; // 1 Z = 1024 E
        const Y = Z * 1000; // 1 Y = 1024 Z

        if (bytes < K) {
            return `${bytes}`; // 小于1K的字节
        } else if (bytes < M) {
            const kilobytes = (bytes / K).toFixed(2);
            return `${kilobytes} K`;
        } else if (bytes < G) {
            const megabytes = (bytes / M).toFixed(2);
            return `${megabytes} M`;
        } else if (bytes < T) {
            const gigabytes = (bytes / G).toFixed(2);
            return `${gigabytes} G`;
        } else if (bytes < P) {
            const terabytes = (bytes / T).toFixed(2);
            return `${terabytes} T`;
        } else if (bytes < E) {
            const petabytes = (bytes / P).toFixed(2);
            return `${petabytes} P`;
        } else if (bytes < Z) {
            const exabytes = (bytes / E).toFixed(2);
            return `${exabytes} E`;
        } else if (bytes < Y) {
            const zettabytes = (bytes / Z).toFixed(2);
            return `${zettabytes} Z`;
        } else {
            const yottabytes = (bytes / Y).toFixed(2);
            return `${yottabytes} Y`;
        }
    }

}


